package com.abc.pro.ui.phone;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.abc.pro.ui.phone.fragment.MainMenuFragment;
import com.abc.pro.ui.phone.fragment.OddFragment;
import com.abc.pro186.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.MenuItem;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainSlidingFragmentActivity extends SlidingFragmentActivity {
	
	private Fragment mContent;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// set the Above View
		/*if (savedInstanceState != null)
			mContent = getSupportFragmentManager().getFragment(
					savedInstanceState, "mContent");*/
		mContent = new OddFragment();
		
		// customize the SlidingMenu
		SlidingMenu sm = getSlidingMenu();
		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		// sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		sm.setBehindWidth(480);
		sm.setFadeDegree(0.35f);
		sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		
		// set the Above View
		setContentView(R.layout.content_frame);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, mContent).commit();

		// set the Behind View
		Fragment menuFragment = new MainMenuFragment();
		setBehindContentView(R.layout.menu_frame);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.menu_frame, menuFragment).commit();
		
		/*getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two);
		getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
		getSupportFragmentManager()
		.beginTransaction()
		.replace(R.id.menu_frame_two, new OddFragment())
		.commit();*/

		
		ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            // actionbar.setDisplayHomeAsUpEnabled(false);
            actionbar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
            // actionbar.setDisplayUseLogoEnabled(true);
            actionbar.setIcon(R.drawable.ic_action_menu_show_main_menu);
            actionbar.setDisplayShowHomeEnabled(true);
            Drawable bg = getResources().getDrawable(R.drawable.action_bar_bg);
            actionbar.setBackgroundDrawable(bg);
        }
        
	}

	public void switchContent(Fragment fragment) {
		mContent = fragment;
		if (fragment == null) {
			return;
		}
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.content_frame, fragment).commit();
		getSlidingMenu().showContent();
	}
	
	public void resetActionBarState() {
        // remove navigation list or navigation tabs
        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        
        // remove custom navigation view
        getSupportActionBar().setDisplayShowCustomEnabled(false);
        getSupportActionBar().setCustomView(null);
        
        // remove all action item
        invalidateOptionsMenu();
    }
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			toggle();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

}
